package com.yongcheon.sms_manager.ui.preference;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.yongcheon.sms_manager.R;
import com.yongcheon.sms_manager.data.preference.SpamNumberData;
import com.yongcheon.sms_manager.vo.SpamNumVO;

/**
 * Created by yongcheon on 2014-12-09.
 */
public class SpamNumCursorAdapter extends CursorAdapter {
    LayoutInflater Inflater;
    SpamNumberData spamNumberData;

    public void setSpamNumberData(SpamNumberData spamNumberData) {
        this.spamNumberData = spamNumberData;
    }

    public SpamNumCursorAdapter(Context context, Cursor c) {
        super(context, c);
        Inflater = LayoutInflater.from(context);
    }
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        View newView = Inflater.inflate(R.layout.spam_num_list_item, parent, false);
        return newView;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        SpamNumVO spamNumVO = spamNumberData.createSpamNumVOFromCursor(cursor);

        TextView phoneNum = (TextView)view.findViewById(R.id.spam_num);
        phoneNum.setText(context.getResources().getString(R.string.number)+" : "+spamNumVO.getAddress());

        TextView title = (TextView)view.findViewById(R.id.spam_num_title);
        title.setText(context.getResources().getString(R.string.desc)+" : "+spamNumVO.getSubject());

//        TextView spam_desc = (TextView)view.findViewById(R.id.spam_desc);
//        spam_desc.setText(context.getResources().getString(R.string.message)+" : "+spamNumVO.getDesc());

        TextView spam_type = (TextView)view.findViewById(R.id.spam_type);
        spam_type.setText(context.getResources().getString(R.string.type)+" : "+spamNumVO.getCategory_2());

        SpamNumLongClickListener longClickListener = new SpamNumLongClickListener(view, spamNumVO, this);
        view.setOnLongClickListener(longClickListener);

//        System.out.println("getEtc : "+spamNumVO.getEtc());
//        System.out.println("getDesc : "+spamNumVO.getDesc());
//        System.out.println("getSubject : "+spamNumVO.getSubject());
//        System.out.println("getCategory_1 : "+spamNumVO.getCategory_1());
//        System.out.println("getCategory_2 : "+spamNumVO.getCategory_2());
//        System.out.println("getCategory_3 : "+spamNumVO.getCategory_3());
//        System.out.println("getAddress : "+spamNumVO.getAddress());
    }
}
